﻿@model NavigationModel
@using CAF.Infrastructure.Core.Domain.Cms.Articles;
@using CAF.WebSite.Mvc.Models.ArticleCatalog;
@using CAF.Infrastructure.Core.Collections
@functions {
    private string GetCssClassForNode(NodePathState state)
    {
        var liClasses = new List<string>();

        if ((state & NodePathState.Parent) == NodePathState.Parent)
        {
            liClasses.Add("dropdown");
        }

        if ((state & NodePathState.Expanded) == NodePathState.Expanded)
        {
            liClasses.Add("expanded");
        }

        if ((state & NodePathState.Selected) == NodePathState.Selected)
        {
            liClasses.Add("active");
        }

        return liClasses.Count > 0 ? String.Join(" ", liClasses) : null;
    }

    private bool ShouldRenderChildren(NodePathState state)
    {
        if (!((state & NodePathState.Parent) == NodePathState.Parent) || !Model.Path.Any())
            return false;

        if ((state & NodePathState.Expanded) == NodePathState.Expanded || (state & NodePathState.Selected) == NodePathState.Selected)
        {
            return true;
        }

        return false;
    }
}
<section class="full-page-title-wrap clearfix"><h2>@Model.Root.Value.Text</h2><em class="full-page-title-line"></em></section>


@if (Model.Root.HasChildren)
{
    <section class="full-page-menu">
        <div class="full-page-menu-content">
            <div class="page-width">
                <ul class="clearfix">
                    @CreateMenu(Model.Root.Children, "")
                </ul>
            </div>
        </div>
    </section>
}

@helper CreateMenu(IEnumerable<TreeNode<MenuItem>> nodes, string menuSelector)
{
    foreach (var node in nodes)
    {
        var state = node.GetNodePathState(Model.Path);
        var url = node.Value.GenerateUrl(this.Url);
        <li class=""><a href="@url">@node.Value.Text</a></li>

    }

}

